package com.zbkj.front.service.impl;

import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.zbkj.common.model.enquiry.PeEnquiry;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.enquiry.ReportRequest;
import com.zbkj.common.request.enquiry.EnquirySaveRequest;
import com.zbkj.common.response.enquiry.ClientEnquiryResponse;
import com.zbkj.common.response.enquiry.EnquiryReportResponse;
import com.zbkj.common.response.project.ClientProjectInfoResponse;
import com.zbkj.common.token.FrontTokenComponent;
import com.zbkj.front.service.PeEnquiryHandleService;
import com.zbkj.service.service.enquiry.IPeEnquiryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Slf4j
@Service
public class PeEnquiryHandleServiceImpl implements PeEnquiryHandleService {
    @Autowired
    private FrontTokenComponent frontTokenComponent;
    @Autowired
    private IPeEnquiryService peEnquiryService;
    @Override
    public boolean saveEnquiryInfo(EnquirySaveRequest saveRequest) {
        Long userId = frontTokenComponent.getLoginUserId();
        PeEnquiry peEnquiry = new PeEnquiry();
        BeanUtils.copyProperties(saveRequest,peEnquiry);
        peEnquiry.setUserId(userId);
        Date currentDate = new Date();
        peEnquiry.setDeleteFlag(0);
        peEnquiry.setCreateTime(currentDate);
        peEnquiry.setUpdateTime(currentDate);
        return peEnquiryService.save(peEnquiry);
    }

    @Override
    public PageInfo<ClientEnquiryResponse> enquiryList(PageParamRequest pageParamRequest) {
        Long userId = frontTokenComponent.getLoginUserId();
        PageInfo<PeEnquiry> page = peEnquiryService.getUserEnquiryList(userId, pageParamRequest);
        List<ClientEnquiryResponse> responseList = Lists.newArrayList();
        for(PeEnquiry enquiry : page.getList()) {
            ClientEnquiryResponse response = new ClientEnquiryResponse();
            BeanUtils.copyProperties(enquiry, response);
            responseList.add(response);
        }
        return CommonPage.copyPageInfo(page, responseList);

    }

    @Override
    public EnquiryReportResponse enquiryReqort(ReportRequest reportRequest) {
        Long userId = frontTokenComponent.getLoginUserId();
        return peEnquiryService.enquiryReqort(userId, reportRequest);
    }
}
